package com.codedancer.campus.enums;

import cn.hutool.core.util.ObjectUtil;
import com.codedancer.campus.common.enums.CodeDbEnum;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * @Author codeworld 商品查询价格区间
 **/
public enum CommodityPriceRegion implements CodeDbEnum {

    ALL(0, "全部"),
    ZERO_TO_FIFTY(1, "0~50"),
    FIFTY_TO_HUNDRED(2, "50～100"),
    HUNDRED_TO_FIVE_HUNDRED(3, "100～500"),
    FIVE_HUNDRED_ABOVE(4, "500+");

    /**
     * 对应的值
     */
    @JsonValue
    private final Integer value;

    /**
     * 对应的名称
     */
    private final String name;

    CommodityPriceRegion(Integer value, String name) {
        this.value = value;
        this.name = name;
    }

    public static CommodityPriceRegion fromValue(Integer value) {
        for (CommodityPriceRegion commodityPriceRegion : CommodityPriceRegion.values()) {
            if (ObjectUtil.equal(commodityPriceRegion.getValue(), value)) {
                return commodityPriceRegion;
            }
        }
        return null;
    }

    @Override
    public Integer getValue() {
        return value;
    }

    public String getName() {
        return name;
    }
}
